//
//  SWNotPayDetailsViewController.m
//  PropertyManager
//
//  Created by 黎世炜 on 2018/11/7.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "SWNotPayDetailsViewController.h"
#import "SWNotPayDetailsTableViewCell.h"
#import "NotPayDetailsModel.h"
#import "OpenFaPiaoTableViewController.h"
@interface SWNotPayDetailsViewController () <UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *sumNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *businessNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *heTongLabel;
@property (weak, nonatomic) IBOutlet UIButton *payButton;
@property (strong, nonatomic) NSMutableArray * datas;
@end

@implementation SWNotPayDetailsViewController

-(instancetype)init{
    if (self = [super init]) {
        self = [[UIStoryboard storyboardWithName:@"NotPayListStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"SWNotPayDetailsViewController"];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    NSArray * strArr = [self.model.keyStr componentsSeparatedByString:@"#"];
    self.businessNameLabel.text = [NSString stringWithFormat:@"广百物业%@缴费通知单",strArr[0]];
    self.sumNumLabel.text = [NSString stringWithFormat:@"¥%.2lf",self.model.money];
    self.heTongLabel.text = [NSString stringWithFormat:@"合同号：%@",strArr[1]];
    for (NSDictionary * dict in self.model.list) {
        NotPayDetailsModel * itemModel = [NotPayDetailsModel yy_modelWithDictionary:dict];
        [self.datas addObject:itemModel];
    }
    if (![strArr[3] isEqualToString:@"2"]) {
        
    }else{
        [self.payButton setTitle:@"开发票" forState:UIControlStateNormal];
        [self.payButton setBackgroundColor:kColorFromHex(0x1E64E4)];
    }
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    SWNotPayDetailsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"SWNotPayDetailsTableViewCell" forIndexPath:indexPath];
    cell.model = self.datas[indexPath.row];
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}

//-(void)setModel:(NotPayModel *)model{
//    _model = model;
//
//    for (NSDictionary * dict in model.list) {
//        NotPayDetailsModel * itemModel = [NotPayDetailsModel yy_modelWithDictionary:dict];
//        [self.datas addObject:itemModel];
//    }
//
//    [self.tableView reloadData];
//}
- (IBAction)clickPayButton:(UIButton *)sender {
    NSArray * strArr = [self.model.keyStr componentsSeparatedByString:@"#"];
    if (![strArr[3] isEqualToString:@"2"]) {//支付
        
    }else{//开发票
        OpenFaPiaoTableViewController * vc = [[OpenFaPiaoTableViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

-(NSMutableArray *)datas{
    if (!_datas) {
        _datas = [NSMutableArray array];
    }
    return _datas;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
